from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


#基类
class Base:

    def __init__(self,driver: WebDriver):
        self.driver = driver
        # self.driver=webdriver.Edge()

    def open_url(self,url):
        self.driver.get(url)

    #封装定位
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver, 20, 0.5).until(lambda driver:driver.find_element(*loc))
            return self.driver.find_element(*loc)
        except Exception as e:
            print("未定位到元素:",loc)

    #点击
    def click(self,loc):
        self.find_element(loc).click()

    def send_keys(self,loc,text):
        self.find_element(loc).send_keys(text)

    #获取元素属性值的方法
    def get_text(self, loc):
        return self.find_element(loc).text

    def quit(self):
        self.driver.quit()

